package cn.szzsi.common.model;

import cn.szzsi.common.model.base.BaseWeixinFansRecord;
import com.jfinal.plugin.activerecord.Db;

/**
 * Created by zhengy on 2017/1/9.
 */
//@TableBind(tableName = "weixin_fans_record",pkName = "id")
public class WeixinFansRecord extends BaseWeixinFansRecord<WeixinFansRecord> {
    public static final WeixinFansRecord dao = new WeixinFansRecord().dao();

    public static final void subscribe(String openid, String status, String sceneid){
        WeixinFansRecord record = new WeixinFansRecord();
        record.set("create_time", System.currentTimeMillis());
        record.set("openid",openid);
        record.set("type",1);
        record.set("status",status);
        record.set("sceneid",sceneid);
        record.save();
    }

    public static final void unsubscribe(String openid){
        Db.update("UPDATE mall_weixin_fans_record set type=0 where openid=?",openid);
        WeixinFansRecord record = new WeixinFansRecord();
        record.set("create_time", System.currentTimeMillis());
        record.set("openid",openid);
        record.set("status",0);
        record.set("type",0);
        record.save();
    }

    public WeixinFansRecord isExitByOpenidAndType(String openid, Integer type){
       return WeixinFansRecord.dao.findFirst("select * from mall_weixin_fans_record where openid=? and type=?",openid,type);
    }
}


























